
var id = document.getElementById('uid_do_check_file').value;

function getUrlRelativePath() {
    var url = document.location.toString();
    var arrUrl = url.split("//");
    var relUrl = arrUrl[1].split("/")[1]
    return relUrl;
}

function do_check_file(id) {
    $.post("/" + getUrlRelativePath() + "/" + "do_check_file", {"uid": id}, function (dataCheckFile) {
        if(dataCheckFile['title']!=undefined&&dataCheckFile['PreviewFileUrl']!=undefined)
        {
            document.getElementById('check_file_title').innerHTML = dataCheckFile['title'];
            document.getElementById('NoPermissioniframe').src = dataCheckFile['PreviewFileUrl'];
        }
        else
        {
            $("#alert-warning").show();
        }
    })
}

function do_check_file_obj(obj) {
    $.post("/" + getUrlRelativePath() + "/" + "do_check_file", {"uid": obj.id}, function (dataCheckFile) {
        if(dataCheckFile['title']!=undefined&&dataCheckFile['PreviewFileUrl']!=undefined)
        {
            document.getElementById('check_file_title').innerHTML = dataCheckFile['title'];
            document.getElementById('NoPermissioniframe').src = dataCheckFile['PreviewFileUrl'];
        }
        else
        {
            $("#alert-warning").show();
        }
    })
}

function do_check_file_revision(id) {
    $.post("/" + getUrlRelativePath() + "/" + "do_check_file_revision", {"uid": id}, function (dataCheckFileRevision) {
        var ul = document.getElementById('information_ul');
        var rowNum = ul.childNodes.length;
        for (i = 1; i < rowNum; i++) {
            ul.removeChild(ul.childNodes[i]);
            rowNum = rowNum - 1;
            i = i - 1;
        }
        var rowNum = dataCheckFileRevision['revisionInfoList'].length;
        for (i = 0; i < rowNum; i++) {
            if(id == dataCheckFileRevision['revisionInfoList'][i][1])
            {
                ul.innerHTML += "<li class='information_li information_li_add' ><a href='javascript:;' id='" + dataCheckFileRevision['revisionInfoList'][i][1] + "' onclick='do_check_file_obj(this);do_change_color(this)'>" + dataCheckFileRevision['revisionInfoList'][i][0] + "&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp" + dataCheckFileRevision['revisionInfoList'][i][4] + "</a></li>";
            }
            else
            {
                ul.innerHTML += "<li class='information_li'><a href='javascript:;' id='" + dataCheckFileRevision['revisionInfoList'][i][1] + "' onclick='do_check_file_obj(this);do_change_color(this)'>" + dataCheckFileRevision['revisionInfoList'][i][0] + "&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp" + dataCheckFileRevision['revisionInfoList'][i][4] + "</a></li>";
            }
        }
    })
}

function do_change_color(obj){
    $(".information_ul li").click(function() {
        $(".information_ul li").removeClass("information_li_add");
        $(this).addClass("information_li_add") ;
    })
}

$(function do_watch() {
    do_check_file(id);
    do_check_file_revision(id);
});
